package com.niiwoo.civet.scheduler.trigger;

import java.util.concurrent.CompletableFuture;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Reference;
import com.niiwoo.activity.stage.service.notify.PersonalizedNotifyActivityDubboService;
import com.niiwoo.civet.account.service.notify.PersonalizedNotifyAccountDubboService;
import com.niiwoo.civet.user.service.notify.PersonalizedNotifyUserDubboService;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
public class PersonalizedNotifyJobTrigger {
	
	@Reference(version = "1.0.0")
	private PersonalizedNotifyUserDubboService personalizedNotifyUserDubboService;

	@Reference(version = "1.0.0")
	private PersonalizedNotifyActivityDubboService personalizedNotifyActivityDubboService;
	
	@Reference(version = "1.0.0")
	private PersonalizedNotifyAccountDubboService personalizedNotifyAccountDubboService;
	
    @Scheduled(cron = "${personalizedNotify.unopenInvestmentAccount}")
    public void unopenInvestmentAccount(){
        try {
            log.info("PersonalizedNotifyJobTrigger.unopenInvestmentAccount start");
			CompletableFuture.runAsync(() -> personalizedNotifyUserDubboService.unopenInvestmentAccount());
            log.info("PersonalizedNotifyJobTrigger.unopenInvestmentAccount end");
        } catch (Exception e) {
			log.error("PersonalizedNotifyJobTrigger.unopenInvestmentAccount异常", e);
        }
    }
    
    @Scheduled(cron = "${personalizedNotify.openInvestmentAccountAfterUnInvestment}")
    public void openInvestmentAccountAfterUnInvestment(){
        try {
            log.info("PersonalizedNotifyJobTrigger.openInvestmentAccountAfterUnInvestment start");
			CompletableFuture.runAsync(() -> personalizedNotifyAccountDubboService.openInvestmentAccountAfterUnInvestment());            
            log.info("PersonalizedNotifyJobTrigger.openInvestmentAccountAfterUnInvestment end");
        } catch (Exception e) {
			log.error("PersonalizedNotifyJobTrigger.openInvestmentAccountAfterUnInvestment异常", e);
        }
    }
    
    @Scheduled(cron = "${personalizedNotify.unusedPrize}")
    public void unusedPrize(){
        try {
            log.info("PersonalizedNotifyJobTrigger.unusedPrize start");
            CompletableFuture.runAsync(() -> personalizedNotifyActivityDubboService.unusedPrize());
            log.info("PersonalizedNotifyJobTrigger.unusedPrize end");
        } catch (Exception e) {
			log.error("PersonalizedNotifyJobTrigger.unusedPrize异常", e);
        }
    }
}